﻿using Microsoft.ManagementConsole.SnapIns.Integration;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Microsoft.ManagementConsole.SnapIns.Controls
{
    public partial class EventLogDetailForm : Form
    {
        private PlanckTime.Entity.EventLog eventLog;
        private PlanckTime.Entity.Task currentTask;


        public EventLogDetailForm(PlanckTime.Entity.EventLog eventLog)
        {
            this.eventLog = eventLog;
        }

        public EventLogDetailForm(PlanckTime.Entity.EventLog eventLog, PlanckTime.Entity.Task CurrentTask)
        {
            InitializeComponent();

            this.eventLog = eventLog;
            this.currentTask = CurrentTask;

            InitializeTaskDetail();
            InitializeEventLogDetail();

        }

        private void InitializeEventLogDetail()
        {
            if (this.eventLog != null)
            {
                lblDateCreatedValue.Text = this.eventLog.DateCreated.ToString();
                lblDescriptionValue.Text = this.eventLog.Description;
                lblTitleValue.Text = this.eventLog.Title;
                lblCreatedByValue.Text = GetUserDisplayName(eventLog.CreatedBy);
                btnAttechmentDownload.Visible = this.eventLog.AttachmentId != Guid.Empty;
            }
        }

        private void InitializeTaskDetail()
        {
            if (this.currentTask != null)
            {
                this.Text = this.currentTask.Name;
            }
        }

        private void btnAttechmentDownload_Click(object sender, EventArgs e)
        {

        }

        private string GetUserDisplayName(Guid userId)
        {
            if (userId != Guid.Empty)
            {
                return PlanckTimeServices.Instance.GetUserDisplayName(userId);
            }

            return "--------------";
        }

    }
}
